<template>
	<view class="container">
		<view class="scrollviewContainer" v-if="cardObj.total==0&&pageInit">
			<u-empty style="padding-top: 300rpx" text="数据为空"
				:width="'400rpx'"
				icon="/static/image/icon_empty_list.png"
				textSize="28rpx"
				mode="data"></u-empty>
		</view>
		<!--头部 -->
		<template v-for="(card, cardIndex) in cardObj.list">
			<view class="namecardContainer" :key="card.id" @click="gotoCustomerDetail(card)">
				<view class="top" style="margin-top: 10rpx;">
					<view class="left">
						<image class="avatar" :src="card.avatar||'/static/img/user_img_ntx.png'" mode="">
						</image>
						<view class="wrapper">
							<view class="name">
								{{card.name||''}}
                <text style="color: #f00;" v-if="isSeller">
                  ({{card.customerSource}})
                </text>
								<template v-if="card.sex<2">
									<span style="margin-left: 10rpx"></span>
									{{sexList[card.sex]}}
								</template>

								<span v-if="!(isReferrer||isChannel)&&card.protectDay&&card.protectDay>=0"
									style="margin-left: 10rpx">保护期剩{{card.protectDay}}天</span>
								<span style="margin-left: 10rpx"
									v-if="!(isReferrer||isChannel)&&card.protectDay&&card.protectDay<0">已过保护期{{0-card.protectDay}}天</span>
							</view>
							<view v-if="(card.salesmanId!=sellerObj.uuid)&&card.salesmanName&&card.salesmanName.length>0" class="name">
								置业顾问：
								<text class="myText">
									{{card.salesmanName}}
								</text>

							</view>
							<view v-if="card.allocateSource!=null&&'sys_allocate'==card.allocateSource" class="name">
								旧顾问：
								<text class="myText">
									{{card.lastSalesmanName||''}}
								</text>
							</view>
							<view class="scanCount">
								<span style="margin-right: 30rpx"
									v-if="!(isReferrer||isChannel)&&card.referrerName">推荐人：{{card.referrerName}}</span>访问{{card.viewTimes}}次
							</view>
							<view class="firstWrapper" v-if="card.firstUserLogText&&card.firstUserLogText.length>0">
								首次访问：{{card.firstUserLogText}}
							</view>
						</view>
					</view>
				</view>
				<view class="middle" style="font-size: 24rpx;">
					<view class="left">
						<!-- <view>{{allocateSourceList[card.allocateSource]}}</view> -->
						<view>{{intentionList[card.intention]}}</view>
						<view class="followTag" v-if="!(isReferrer||isChannel)">{{card.followTab}}</view>
					</view>
					<view class="right text-2line-ellipsis" style="font-size: 24rpx;"
						v-if="card.lastUserLogText.length">
						最近访问：{{card.lastUserLogText||''}}
					</view>
				</view>
				<view class="bntWrapper">
					<view v-if="card.phone&&card.phone.length>0" class="leftBtn" @click.stop="gotoPhone(card.phone)">
						<image class="icon" src="../static/image/icon_visitor_tel.png" mode=""></image>
						联系客户
					</view>
				</view>
			</view>
		</template>
		<view class="" style="height: 150rpx;">

		</view>
	</view>

</template>

<script>
	import {
		mapState
	} from 'vuex';

	let timeId = null
	let that = null
	const api = require("@/static/js/api.js")
	const utils = require("@/static/js/utils.js")
	const Config = require("@/config.js")
	const TAB_sortField = ['lastLoginTime', 'createTime', 'viewTimes', 'protectLimitDay', 'followTime', 'followTime',
		'result'
	];


	export default {
		computed: {
			...mapState({
				hasLogin: state => state.userInfo.hasLogin,
				isAuthPhone: state => state.userInfo.isAuthPhone,
				isAuthUserInfo: state => state.userInfo.isAuthUserInfo,
				isSeller: state => state.userInfo.isSeller,
				isReferrer: state => state.userInfo.isReferrer,
				isChannel: state => state.userInfo.isChannel,
				sellerObj: state => state.userInfo.sellerObj,
				buyerObj: state => state.userInfo.buyerObj,
				shopInfo: state => state.userInfo.shopInfo,
			}),

		},
		data() {
			return {
				pageInit: false,
				cardObj: {
					list: [],
					loadStatus: "loading",
					pageIndex: 1,
					curPageIndex: 0,
					total: 0,
				},
				type: 0,
				intentionList: [
					'未知意向',
					'低意向',
					'中意向',
					'高意向',
					'必买',
					'已购买',
					'无意向'
				],
			};
		},

		components: {

		},
		props: {
			value: {
				type: Boolean,
				default: false,
			},
			onShow: {
				type: Boolean,
				default: true,
			}
		},

		onLoad(options) {
			that = this
			this.type = options.type

			uni.setNavigationBarTitle({
				title: this.type==0?'今日访客':'今日获客' 
			})
		},
		onReachBottom(){
			that.getCustomerList()
		},
		onShow(){
			this.clearListShow(this.cardObj)
			this.getCustomerList()
		},
		methods: {
			gotoCustomerDetail(card) {
				if (!this.shopInfo.allowEditUser) {
					return;
				}
				if (this.isReferrer == 1) {
					return;
				}
				this.backupCustomerItem = card;
				uni.navigateTo({
					url: '/pages/shop/customer/customerDetail?id=' + card.id
				})
			},

			gotoPhone(phone) {
				uni.makePhoneCall({
					// 手机号
					phoneNumber: phone,
					// 成功回调
					success: (res) => {
						console.log('调用成功!')
					},
					// 失败回调
					fail: (res) => {
						console.log('调用失败!')
					}
				});
			},


			getCustomerList() {
				let that = this
				console.log("getCustomerList:", 1);
				if (that.cardObj.curPageIndex != that.cardObj.pageIndex) {
					that.cardObj.curPageIndex = that.cardObj.pageIndex
					
					uni.showLoading({
						title: "加载中..."
					})
					var obj = {
						
					}
					
					if (this.type == 1){
						obj.createdToday = true
						obj.hasPhone = true
					}else{
						obj.period = 0
					}
							
					api.getCustomerList({
						param: {
							limit: 10,
							page: that.cardObj.pageIndex,
							salesmanId: that.buyerObj.salesmanId,
							...obj
						}
					}).then(res => {
						console.log(res)
						if (res.code == 0) {

							that.pushListShow(that.cardObj, res.data)
							that.cardObj.total = res.count;
						}
					}).finally(t => {		
						uni.hideLoading()				
						this.pageInit = true
					})
				}
			},
			/**
			 * @description: 列表中添加数据
			 * @param {number} id   u-tabs-swiper的当前ID
			 * @param {list}  列表
			 * @return void
			 */
			pushListShow(srcObj, pushlist) {
				if (pushlist && pushlist.length > 0) {
					for (let i = 0; i < pushlist.length; i++) {
						pushlist[i].intention = pushlist[i].intention || 0
						pushlist[i].allTimes = pushlist[i].allTimes || ''
						pushlist[i].date = pushlist[i].date || ''
						pushlist[i].avatar = pushlist[i].avatar || ''
						pushlist[i].nickname = pushlist[i].nickname || ''
						pushlist[i].sex = pushlist[i].sex || 2
						pushlist[i].aiIntention = pushlist[i].aiIntention || ''
						pushlist[i].visitorStatusId = 0;
	

						if (pushlist[i].lastUserLog && pushlist[i].lastUserLog.createTime) {
							pushlist[i].lastUserLogText = pushlist[i].lastUserLog.createTime + ' ' + (pushlist[i]
								.lastUserLog.content || '');
						} else {
							pushlist[i].lastUserLogText = ""
						}

						if (pushlist[i].firstUserLog && pushlist[i].firstUserLog.createTime) {
							pushlist[i].firstUserLogText = pushlist[i].firstUserLog.createTime + ' ' + (pushlist[i]
								.firstUserLog.content || '');
						} else {
							pushlist[i].firstUserLogText = ""
						}

						if (pushlist[i].phone &&
							pushlist[i].phone.length == 11 &&
							/^\d+$/.test(pushlist[i].phone.slice(0, 3)) &&
							/^\d+$/.test(pushlist[i].phone.slice(7, 11)) &&
							pushlist[i].phone.slice(3, 7) == "****"
						) {
							pushlist[i].hasAllPhoneNumber = false
						} else {
							pushlist[i].hasAllPhoneNumber = true
						}
						//==去重
						for (var j in srcObj.list) {
							if (srcObj.list[j].id == pushlist[i].id) {
								srcObj.list.splice(j, 1)
							}
						}

						srcObj.list.push(pushlist[i])
					}
					srcObj.pageIndex++;

					if (pushlist.length == 10) {
						srcObj.loadStatus = "loadmore"
					} else {
						srcObj.loadStatus = "nomore"
					}
					console.log("srcObj:", srcObj)
				} else {
					srcObj.loadStatus = "nomore"
				}
			},

			//----清空列表
			clearListShow(srcObj) {
				srcObj.curPageIndex = 0;
				srcObj.total = 0;
				srcObj.pageIndex = 1;
				srcObj.list.splice(0, srcObj.list.length)
			},
		},
	}
</script>

<style>
	page{
		background-color: #f3f3f3;
	}
</style>

<style lang="scss">
	.container {
		width: 100vw;
		background-color: #f3f3f3;
	}

	.scrollviewContainer {
		width: 100%;
		background-color: #f3f3f3;

		.aiIntention {
			margin-bottom: 10rpx
		}

		.vistorTag {
			margin-top: 5px;
			bottom: 0;
			left: 0;
			width: 108rpx;
			height: 44rpx;
			background-color: #44b7ff;
			border-radius: 10rpx;
			font-size: 24rpx;
			color: #FFFFFF;
			line-height: 44rpx;
			text-align: center;
			display: flex;
			align-items: center;
			justify-content: center;

			.icon {
				width: 18rpx;
				height: 18rpx;
				// margin-left: 5rpx;
			}
		}

		.followTag {
			margin-top: 5px;
			bottom: 0;
			left: 0;
			width: 108rpx;
			height: 44rpx;
			background-color: darkgray;
			border-radius: 10rpx;
			font-size: 21rpx;
			color: #FFFFFF;
			line-height: 44rpx;
			text-align: center;
			display: flex;
			align-items: center;
			justify-content: center;

			.icon {
				width: 18rpx;
				height: 18rpx;
				// margin-left: 5rpx;
			}
		}
	}

	.headerContainer {
		width: 750rpx;
		background-color: #FFFFFF;
		display: flex;
		flex-direction: column;
		align-items: center;
		border-bottom: #F3F3F3 solid 1px;
		padding-top: var(--status-bar-height);
		position: sticky;
		top: 0;
		left: 0;
		z-index: 886;

		.searchItem {
			margin-top: 30rpx;
			width: 600rpx;
			margin-bottom: 30rpx;
		}

		.selected {
			height: 80rpx;
			position: absolute;
			right: 30rpx;
			z-index: 12;
			top: 0rpx;
			display: flex;
			align-items: center;
			overflow-y: scroll;
			font-size: 26rpx;
			color: #888;

			.icon {
				height: 30rpx;
				width: 30rpx;
				margin-right: 15rpx;
			}
		}

		.selectedColorEn {
			color: #1890FF;
		}

		.bottomWrapper {
			display: flex;
			align-items: center;
			justify-content: space-between;
			width: 750rpx;
			margin-top: 20rpx;

			.left {
				height: 80rpx;
				padding: 0 30rpx;
				font-size: 28rpx;
				line-height: 80rpx;
				border-top: 1px #F3F3F3 solid;

				.tag {
					font-size: 35rpx;
					font-weight: bolder;
					margin: 0 15rpx;
					color: #1890FF;
				}
			}

			.right {
				display: flex;
				align-items: center;

				.recordWrapper {
					display: flex;
					align-items: center;
					font-size: 26rpx;
					margin-right: 30rpx;
					background-color: #1890FF;
					color: #ffffff;
					height: 60rpx;
					padding: 0 20rpx;
					border-radius: 30rpx;
				}

				.addWrapper {
					height: 45rpx;
					padding: 0 20rpx;
					border-radius: 30rpx;
					border: #1890FF 1px dotted;
					display: flex;
					align-items: center;
					font-size: 24rpx;
					margin-right: 30rpx;
					color: #1890FF;

					.icon {
						width: 40rpx;
						height: 40rpx;
						margin-right: 10rpx;
					}
				}
			}

		}
	}

	.selectContainer {
		width: 650rpx;
		display: flex;
		flex-direction: column;
		background-color: #fff;
		border-radius: 20rpx;
		align-items: center;
		height: 1000rpx;
		position: relative;

		.header {
			padding: 20rpx;
			width: 100%;
			color: #333333;
			font-size: 32rpx;
			font-weight: bold;
			text-align: center;
			border-bottom: solid 1px #f8f8f8;
		}

		.contentWraper {
			width: 100%;
			margin-bottom: 40rpx;

			.title {
				margin-left: 20rpx;
				color: #333333;
				font-weight: bold;
				font-size: 30rpx;
			}

			.content {
				display: flex;
				flex-wrap: wrap;
				align-items: center;

				.item {
					background-color: #f6f6f6;
					color: #888;
					width: 180rpx;
					height: 70rpx;
					border-radius: 35rpx;
					line-height: 70rpx;
					font-size: 28rpx;
					text-align: center;
					padding: 0 20rpx;
					margin-left: 20rpx;
					margin-top: 30rpx;
				}

				.salesTitle {
					color: #333333;
					width: 210rpx;
					height: 70rpx;
					line-height: 70rpx;
					border-radius: 35rpx;
					text-align: left;
					margin-top: 30rpx;
				}

				.itemEn {
					color: #FFFFFF;
					background-color: #1890FF;
				}

				.text {
					height: 70rpx;
					margin-left: 20rpx;
					margin-top: 30rpx;
					line-height: 70rpx;
				}
			}
		}

		.btnWrapper {
			display: flex;
			justify-content: space-evenly;
			width: 100%;
			padding-bottom: 50rpx;
			// margin-bottom: 50rpx;
			margin-top: 40rpx;
			position: absolute;
			bottom: 0;

			.btn1 {
				border: 1px #1890FF solid;
				width: 250rpx;
				height: 80rpx;
				color: #1890FF;
				line-height: 80rpx;
				text-align: center;
				font-size: 28rpx;
				border-radius: 40rpx;
			}

			.btn2 {
				background-color: #1890FF;
				width: 250rpx;
				height: 80rpx;
				font-size: 28rpx;
				color: #FFFFFF;
				line-height: 80rpx;
				text-align: center;
				border-radius: 40rpx;
			}
		}
	}

	.namecardContainer {
		width: 714rpx;
		// height: 372rpx;
		background: #FFFFFF;
		box-shadow: 2rpx 2rpx 8rpx 4rpx #EEEEEE;
		border-radius: 20rpx;
		padding: 30rpx;
		margin-top: 30rpx;
		margin-left: 18rpx;
		position: relative;

		.tagWrapper {
			position: absolute;
			right: 0;
			top: 0;
			color: #ffffff;
			background-color: #ff0000;
			height: 40rpx;
			padding: 0 10rpx;
			line-height: 40rpx;
			border-radius: 0 20rpx 0 20rpx;
		}

		.stepContainer {
			height: 100rpx;

			.stepWrapper {
				width: 550rpx;
				margin-left: 50rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;
				height: 50rpx;

				.dropWrapperEn {
					border: solid 3rpx #eb6100;
				}

				.dropWrapperDis {
					border: solid 3rpx #7d7d7d;
				}

				.dropWrapper {
					width: 23rpx;
					height: 23rpx;
					background-color: #ffffff;
					position: relative;
					border-radius: 50%;

					.text {
						position: absolute;
						top: 40rpx;
						left: 50%;
						transform: translateX(-50%);
						width: 80rpx;
						font-size: 20rpx;

						text-align: center;
					}

					.textEn {
						color: #eb6100;
					}

					.textDis {
						color: #7d7d7d;
					}
				}

				.lineWrapperEn {
					width: 120rpx;
					height: 3rpx;
					background-color: #eb6100;
				}

				.lineWrapperDis {
					width: 120rpx;
					height: 3rpx;
					background-color: #7d7d7d;
				}
			}
		}

		.top {
			display: flex;
			justify-content: space-between;

			.left {
				display: flex;
				align-items: center;

				.avatar {
					width: 98rpx;
					height: 98rpx;
					margin-right: 30rpx;
					border-radius: 50%;
				}

				.wrapper {
					font-size: 28rpx;
					color: #666666;
					line-height: 40rpx;

					.name {
						margin-bottom: 15rpx;

						.myText {
							font-size: 24rpx;
							color: #999999;
						}
					}

					.scanCount {
						margin-bottom: 15rpx;
					}

					.firstWrapper {
						margin-left: 15rpx;
						width: 466rpx;
						// height: 80rpx;
						font-size: 22rpx;
						font-weight: 400;
						color: #999999;
						line-height: 40rpx;
						margin-bottom: 15rpx;
					}
				}
			}

			.right {
				font-size: 32rpx;
				font-weight: 600;
				color: #5E9FFD;
			}

		}

		.middle {
			width: 100%;
			margin-top: 5rpx;
			display: flex;
			align-items: center;

			.left {
				width: 110rpx;
				// height: 40rpx;
				background: #F4F4F4;
				border-radius: 8rpx;
				text-align: center;
				font-size: 24rpx;
				color: #666666;
				line-height: 40rpx;
				margin-right: 30rpx;
			}

			.right {
				width: 466rpx;
				// height: 80rpx;
				font-size: 28rpx;
				font-weight: 400;
				color: #999999;
				line-height: 40rpx;
			}
		}

		.channelInfoWrapper {
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 10rpx 0;

			.left {
				width: 500rpx;
			}

			.right {
				width: 50rpx;
				height: 50rpx;
			}
		}

		.bottom {
			display: flex;
			justify-content: flex-end;
			width: 100%;
			// margin-left: 250rpx;
			margin-top: 56rpx;

			.item {
				width: 188rpx;
				height: 66rpx;
				background: rgba(94, 159, 253, 0.06);
				border-radius: 33rpx;
				// opacity: 0.06;
				display: flex;
				justify-content: center;
				align-items: center;
				font-size: 28rpx;
				color: #666666;
				margin-left: 22rpx;

				.icon {
					width: 54rpx;
					height: 54rpx;
					margin-right: 22rpx;
				}
			}
		}

		.bntWrapper {
			display: flex;
			margin-top: 30rpx;
			width: 100%;
			justify-content: flex-end;

			.leftBtn {
				padding: 0 20rpx;
				height: 50rpx;
				background-color: #ffffff;
				border-radius: 25rpx;
				border: solid 2rpx #16a5fe;
				font-size: 24rpx;
				color: #16a5fe;
				display: flex;
				justify-content: center;
				align-items: center;
				margin-left: 22rpx;

				.icon {
					width: 32rpx;
					height: 32rpx;
					margin-right: 5rpx;
				}
			}

			.rightBtn {
				width: 188rpx;
				height: 66rpx;
				background-color: #16a5fe;
				border-radius: 33rpx;
				font-size: 32rpx;
				color: #FFFFFF;
				display: flex;
				justify-content: center;
				align-items: center;
				margin-left: 22rpx;

				.icon {
					width: 32rpx;
					height: 32rpx;
					margin-right: 10rpx;
				}
			}
		}
	}

	.commitContainer {
		width: 650rpx;
		background: #FFFFFF;
		display: flex;
		align-items: center;
		flex-direction: column;

		.item {
			width: 100%;
			display: flex;
			align-items: center;
			padding: 20rpx 0;
			border-bottom: 1px solid #F3F3F3;

			.left {
				margin-left: 30rpx;
				height: 40rpx;
				width: 130rpx;
				font-size: 28rpx;
				color: #3D3D3D;
				line-height: 40rpx;
				margin-right: 40rpx;
			}

			.middle {
				min-height: 40rpx;
				width: 387rpx;
				line-height: 40rpx;
				font-size: 28rpx;
				color: #333333;
				// word-wrap:break-word;
			}

			.right {
				width: 24rpx;
				height: 24rpx;
			}
		}

		.title {
			// width: 120rpx;
			height: 42rpx;
			font-size: 30rpx;
			color: #1F1F1F;
			line-height: 42rpx;
			margin-top: 48rpx;
			margin-bottom: 18rpx;
		}

		.phone {
			display: flex;
			align-items: center;
			margin-top: 30rpx;

			.left {
				font-size: 30rpx;
				color: #999999;
				line-height: 42rpx;
			}

			.right {
				margin-left: 60rpx;
				padding: 0 15rpx;
				width: 290rpx;
				height: 72rpx;
				line-height: 72rpx;
				border-radius: 10rpx;
				box-sizing: content-box;
				color: #333333;
			}

			.rightBorder {
				border: 1rpx solid #BBBABA;
			}

			.rightClick {
				color: #666666;
				background-color: #eeeeee;
				text-align: center;
			}

			.pasteBtn {
				background-color: #1890FF;
				color: #ffffff;
				font-size: 25rpx;
				line-height: 60rpx;
				padding: 0 20rpx;
				height: 60rpx;
				text-align: center;
				margin-left: 15px;
				border-radius: 10rpx;
			}
		}

		.name {
			display: flex;
			align-items: center;
			margin-top: 30rpx;

			.left {
				font-size: 30rpx;
				color: #999999;
				line-height: 42rpx;
			}

			.right {
				margin-left: 60rpx;
				padding: 0 15rpx;
				width: 400rpx;
				height: 72rpx;
				box-sizing: content-box;
				line-height: 72rpx;
				border-radius: 10rpx;
				border: 1rpx solid #BBBABA;
				color: #333333;
			}
		}

		.btnWrapper {
			display: flex;
			justify-content: center;
			margin-top: 100rpx;
			margin-bottom: 50rpx;

			.btn1 {
				width: 240rpx;
				height: 72rpx;
				border-radius: 37rpx;
				border: 1px solid #BBBABA;
				font-size: 28rpx;
				color: #333333;
				margin-right: 90rpx;
				line-height: 72rpx;
				text-align: center;
			}

			.btn2 {
				width: 240rpx;
				height: 72rpx;
				background: #5E9FFD;
				border-radius: 37rpx;
				font-size: 28rpx;
				color: #FFFFFF;
				line-height: 72rpx;
				text-align: center;
			}
		}
	}

	.sortWrapper {
		margin-left: 20rpx;
		font-size: 24rpx;
		color: #1777ff;
		display: flex;
		line-height: 60rpx;
		align-items: center;
	}

	.listContainer {
		width: 100%;
		display: flex;
		flex-direction: column;
		align-items: center;

		.header {
			width: 750rpx;
			height: 0rpx;
		}

		.itemContainer {
			width: 690rpx;
			height: 179rpx;
			background-color: #ffffff;
			border-radius: 20rpx;
			display: flex;
			align-items: center;
			margin-top: 32rpx;

			.avatar {
				width: 120rpx;
				height: 120rpx;
				margin-right: 20rpx;
				margin-left: 24rpx;
				border-radius: 50%;
				overflow: hidden;
			}

			.middle {
				margin-right: 40rpx;

				.top {
					width: 313rpx;
					font-size: 32rpx;
					color: #121212;
					margin-bottom: 14rpx;
				}

				.bottom {
					width: 313rpx;
					font-size: 24rpx;
					;
					line-height: 35rpx;
					color: #999999;
				}
			}

			.btn {
				width: 140rpx;
				height: 56rpx;
				background-color: #ff7927;
				border-radius: 28rpx;
				font-size: 28rpx;
				color: #ffffff;
				display: flex;
				align-items: center;
				justify-content: center;

				.icon {
					width: 22rpx;
					height: 22rpx;
					margin-right: 10rpx;
				}
			}
		}
	}


	.updateAllPhone {
		width: 100%;
		display: flex;
		justify-content: space-between;

		.left {}

		.right {
			display: flex;
			align-items: center;

			.phoneContainer {
				font-size: 24rpx;
			}

			.updatePhoneBtnWrapper {
				background-color: #ff7927;
				color: #ffffff;
				font-size: 25rpx;
				height: 50rpx;
				line-height: 50rpx;
				padding: 0 15rpx;
				margin-left: 10rpx;
				border-radius: 10rpx;
			}
		}
	}
</style>